import 'package:flutter/material.dart';

import '../../utils/throttle.dart';

/// 对于点击响应限流的widget
// ignore: must_be_immutable
class ThrottleTapWidget extends StatefulWidget {
  /// 待封装的子widget
  final Widget child;

  /// 点击响应的延迟时间
  /// 默认为500ms
  final Duration delayTime;

  final VoidCallback throttleTap;

  ThrottleTapWidget({
    super.key,
    required this.child,
    required VoidCallback onTap,
    this.delayTime = const Duration(milliseconds: 500),
  }) : throttleTap = throttle(onTap, delayTime);

  @override
  State<StatefulWidget> createState() => _ThrottleTapWidgetState();
}

class _ThrottleTapWidgetState extends State<ThrottleTapWidget> {
  @override
  Widget build(BuildContext context) => GestureDetector(
        onTap: widget.throttleTap,
        child: widget.child,
      );
}
